using System;
using System.Collections.Generic;
using System.Text;

using System.Windows.Forms;

namespace org.synthful.Windows.Forms
{
    /// <summary>
    /// Offered under Apache Public Licence 2.0
    /// synthful.org
    /// blessedgeek [@] synthful.org
    /// </summary>
    public class FileDialogUtil
    {
        static public void setFileDialog(FileDialog openFileDialog,
            string fullFileName, string filter, string title, string extension, string path)
        {
            openFileDialog.Filter = filter;
            openFileDialog.Title = title;
            openFileDialog.DefaultExt = extension;
            openFileDialog.InitialDirectory = path.Replace('/', '\\');
            openFileDialog.FileName = fullFileName.Replace('/', '\\');
        }

        static public string openFileDialog(
            FileDialog openFileDialog, string fullFileName,
            string filter, string title, string extension, string path)
        {
            setFileDialog(openFileDialog, fullFileName, filter, title, extension, path);

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                return openFileDialog.FileName;
            }
            return null;
        }

        static public string browseFolderDialog(
            FolderBrowserDialog folderBrowserDialog,
            Environment.SpecialFolder rootFolder,
            string preSelectedPath)
        {
            folderBrowserDialog.ShowNewFolderButton = true;
            folderBrowserDialog.RootFolder = rootFolder;
            folderBrowserDialog.SelectedPath = preSelectedPath;

            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                return folderBrowserDialog.SelectedPath;
            }
            return null;
        }
    }
}
